<?php
//二维码管理

namespace Supplier\Controller;
use Think\Controller;
class QrcodeController extends CommonController {
     //添加商品
    public function addGoods()
    {
        $field = array('term_id','name','parent_id');  
        $row = $this->allCategory($field);  
        //生成无限极分类  
        $list=$this->tree($row);  
        $this->assign('row',$list); 
        $this->assign('supplier_id',I('id')); 

        $this->display('addgoods');
    }
    //  添加商品  表单处理
    public function addGoodsSub()
    {
        if(IS_POST)
        {
            $data = I('post.');
            // var_dump($data);
            // die;
           // $data['goods_sn'] = '111111';
           if(!$data['goods_sn'])
           {
            $data['goods_sn'] = time().rand(0,9).rand(0,9);
           }
            $re = M('goods')->add($data);
            if($re)
           {
                $id = $_SESSION['supplier']['supplier_id'];
                $this->success('添加成功',U("/Supplier/Qrcode/goodsList/supplier_id/$id"));
           }else
           {
                $this->error('请填写有效的信息！');
           }
        }
    }
    //商品列表
    public function  goodsList()
    {
        $supplier_id = I('get.supplier_id');   
        $goods_name = I('post.goods_name');   
        //print_r(I('get.'));
        $Obj = M('goods'); // 实例化User对象
        //$map = array('status'=>'1');
        $where = "a.supplier_id=".$supplier_id;
        if($goods_name)
        {
            $where .= " and a.goods_name like '%$goods_name%'";
        }
        //echo $where;
        $count      = $Obj
                    ->alias('a')
                    ->field('a.*,b.supplier_name')
                    ->join("left join fwzs_security as b on b.supplier_id = a.supplier_id ")
                    ->order('goods_id desc')
                    ->where($where)
                    ->count();// 查询满足要求的总记录数
        $Page       = new \Think\Page($count,15);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        // $Page->setConfig('prev',"上一页");
        // $Page->setConfig('next',"下一页");
        // 
        $Page->setConfig('header','<span class="total">共<b>%TOTAL_ROW%</b>条数据，第<b>%NOW_PAGE%</b>页/共<b>%TOTAL_PAGE%</b>页</span>');
        $Page->setConfig('prev','上一页');
        $Page->setConfig('next','下一页');
        $Page->setConfig('last','末页');
        $Page->setConfig('first','首页');
        $Page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
        $show       = $Page->show();// 分页显示输出// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
        $list = $Obj
        ->alias('a')
        ->field('a.*,b.supplier_name')
        ->join("left join fwzs_security as b on b.supplier_id = a.supplier_id ")
        ->order('goods_id desc')
        ->where($where)
        ->limit($Page->firstRow.','.$Page->listRows)
        ->select();
       // echo $Obj->getLastSql();
        foreach ($list as $key => $value) {
            $con = array(
                'supplier_id'=>$value['supplier_id'],
                'goods_id'=>$value['goods_id'],

                );
            $list[$key]['qrnum'] = M('security_qr')->where($con)->count();
           // echo M('security_qr')->getLastSql();
        }
        //print_r($list);
        $this->assign('listinfo',$list);// 赋值数据集
        $this->assign('page',$show);// 赋值分页输出 
        $this->assign('supplier_id',I('supplier_id'));// 商家ID 
         
        $this->display('goods_list');
    }
    //生成二维码
    public function creatQr()
    {
        // $goods_id = I('get.goods_id');
        // $supplier_id = I('get.supplier_id');
        $this->assign('data',I('get.'));
        $this->display('creatqr');
    }
    //生成二维码  处理提交数据
    public function creatQrSub()
    {

        $goods_id = I('post.goods_id',0);
        $supplier_id = I('post.supplier_id',0);
        // 发放数量
        $send_sum = I('post.send_sum',1);
        //扫描次数
        $number = I('post.number',0);

        $wx_id = I('post.wx_id',0);
        // print_r(I('post.')); 
        $j=0;
        while ($j < $send_sum)
        {
            $returnStr = $this->qr_sn();            
            $qr_sn = M('security_qr')->where('qr_sn='.$returnStr)->getField('qr_sn');
            if (!$qr_sn)
            {
               // $db->query("INSERT INTO ".$ecs->table('security_qr')." (supplier_id, goods_id,qr_sn, number,add_time) VALUES('$supplier_id', '$goods_id', '$returnStr', '$number', '$add_time')");
                $data = array(
                        'supplier_id' => $supplier_id,
                        'goods_id' => $goods_id,
                        'qr_sn' => $returnStr,
                        'number' => $number,
                        'wx_id' => $wx_id,
                        'add_time' => time(),
                    );
                M('security_qr')->add($data);
                $j++;

            }
        }
        $id = $_SESSION['supplier']['supplier_id'];
        $this->success('新增成功', U("/Supplier/Qrcode/goodsList/supplier_id/$id"));
    }
    //随机创建16位数
    function qr_sn(){
        $returnStr = substr(strrev(microtime()), 0, 3) .substr(strtotime(date("Y-m-d", time())), 0, 3) . substr(strrev(microtime()), 0, 3) . substr(mt_rand(), 0, 4) . substr(rand(), 0, 3);
        return $returnStr;
    }
    //基本信息
    public function goodsInfo()
    {
        $goods_id = I('get.goods_id');//分类ID
        $term_id = M('goods')->where('goods_id='.$goods_id)->getField('term_id');

       
        $otherinfo = M('field')->where('term_id='.$term_id)->select();
        $data = M('security_basics')->where(I('get.'))->find();
        $this->assign('data',I('get.'));
    //    if($data[''])
        foreach ($otherinfo as $key => $value) {
            if($value['form_type']=='radio')
            {
                //echo '1111';
                $otherinfo[$key]['setting'] = explode(',',$value['setting']);
            }
        }
        $sql = "show tables like 'fwzs_security_info_".$term_id."'";
        
        $Model = M();
        // var_dump($term_id);
        // die;
        $result = $Model->query($sql);
         
        if(!empty($result))
        {
            $buchonginfo = M('security_info_'.$term_id)->where('goods_id='.$goods_id)->find();
        }else{
            $buchonginfo = '';
        }
        
        $this->assign('info',$data);
        $this->assign('buchonginfo',$buchonginfo);
        $this->assign('otherinfo',$otherinfo);
        $this->display('goodsinfo');
    }









        // $goods_id = I('get.goods_id');
        // $term_id = M('goods')->where('goods_id='.$goods_id)->getField('term_id');
        // $otherinfo = M('field')->where('term_id='.$term_id)->select();
        // $data = M('security_basics')->where(I('get.'))->find();
        // $this->assign('data',I('get.'));
        // foreach ($otherinfo as $key => $value) {
        //     if($value['form_type']=='radio')
        //     {
        //         $otherinfo[$key]['setting'] = explode(',',$value['setting']);
        //     }
        // }
        // $buchonginfo = M('security_info_'.$term_id)->where('goods_id='.$goods_id)->find();
        // $this->assign('info',$data);
        // $this->assign('buchonginfo',$buchonginfo);
        // $this->assign('otherinfo',$otherinfo);
        // $this->display('goodsinfo');


    //商品信息  添加  修改
    public function addGoodsinfoSub()
    {
        header("Content-type:text/html;charset=utf-8");
        $goods_id = I('post.goods_id','');
        $supplier_id = I('post.supplier_id',''); 
        // $supplier_id = empty($_REQUEST['supplier_id']) ? '' : trim($_REQUEST['supplier_id']);
        // $sql = "SELECT count(*) FROM ecs_security_basics where goods_id = $goods_id";
        // $sfy = $db->GetOne($sql);
        $sfy = M('security_basics')->where('goods_id='.$goods_id)->count();
        $data = array(
            'manufacturer' =>$_POST['manufacturer'],
            'is_manufacturer'=>I('post.is_manufacturer',0),//生产厂商
             'regaddress'=>$_POST['regaddress'],//注册地址
             //企业类别entcategory
            'entcategory'=>$_POST['entcategory'],
            'orgcode'=>$_POST['orgcode'],//组织机构代码
            'mainproduct'=>$_POST['mainproduct'],//主打产品
            'producer'=>$_POST['producer'],//产地
            'is_producer'=>I('post.is_producer',0),
            'brands'=>$_POST['brands'],//品牌
            'is_brands'=>I('post.is_brands',0),//品牌
            'productiondata'=>$_POST['productiondata'],//生产日期
            'deadlines'=>$_POST['deadlines'],//有效期限
            'is_deadlines'=>I('post.is_deadlines',0),
            // 'testitem'=>$_POST['testitem'],
            // 'is_testitem'=>$_POST['is_testitem'],
            // 'detection'=>$_POST['detection'],
            // 'is_detection'=>$_POST['is_detection'],
            // 'detectionunit'=>$_POST['detectionunit'],
            // 'is_detectionunit'=>$_POST['is_detectionunit'],
            // 'detectiontime'=>$_POST['detectiontime'],
            // 'is_detectiontime'=>$_POST['is_detectiontime'],
            'limitedperiod'=>$_POST['limitedperiod'],//有限期限
            'is_limitedperiod'=>I('post.is_limitedperiod',0),
            'productionbatch'=>$_POST['productionbatch'],//生产批次
            'is_productionbatch'=>I('post.is_productionbatch',0),
            'dcontent'=>$_POST['dcontent'],//商家简介
            'fuzeren'=>$_POST['fuzeren'],//负责人
            'add_time'=>$_POST['add_time'],//添加时间
            'sort_order'=>$_POST['sort_order'],//排序
            'is_open'=>$_POST['is_open'],//是否显示
            // 'brands'=>$_POST['brands'],
            // 'is_brands'=>$_POST['is_brands'],

            // 'pinzhong'=>$_POST['pinzhong'],
            // 'is_pinzhong'=>$_POST['is_pinzhong'],
            // 'caibushijian'=>$_POST['caibushijian'],
            // 'is_caibushijian'=>$_POST['is_caibushijian'],
            // 'zhizuoshijian '=>$_POST['zhizuoshijian '],
            // //'is_zhizuoshijian '=>$_POST['is_zhizuoshijian '],
            // 'jinghanliang'=>$_POST['jinghanliang'],
            // 'is_jinghanliang'=>$_POST['is_jinghanliang'],
            // 'guige'=>$_POST['guige'],
            // 'is_guige'=>$_POST['is_guige'],
            // 'baozhiq'=>$_POST['baozhiq'],
            // 'is_baozhiq'=>$_POST['is_baozhiq'],
            // 'ccfangf'=>$_POST['ccfangf'],
            // 'is_ccfangf'=>$_POST['is_ccfangf'],
            // 'nianling'=>$_POST['nianling'],
            // 'is_nianling'=>$_POST['is_nianling'],
            // 'sptjj'=>$_POST['sptjj'],
            // 'is_sptjj'=>$_POST['is_sptjj'],

            // //2017-2-24新增
            // 'regaddress'=>$_POST['regaddress'],
            // 'entcategory'=>$_POST['entcategory'],
            // 'orgcode'=>$_POST['orgcode'],
            // 'mainproduct'=>$_POST['mainproduct'],
            'lxtel'=>$_POST['lxtel'],//电话
            'lxurl'=>$_POST['lxurl'],//网址
            // 'flavor'=>$_POST['flavor'],
            // 'materials'=>$_POST['materials'],
            // 'productiontime'=>$_POST['productiontime'],
            // 'storagecondition'=>$_POST['storagecondition'],
            // 'productstandard'=>$_POST['productstandard'],
            'salesarea'=>$_POST['salesarea'],
            'shipin'=>$_POST['shipin'],//视频简介
            //  //20170412新增
            // 'links1_name'=>$_POST['links1_name'],
            // 'links2_name'=>$_POST['links2_name'],
            // 'links3_name'=>$_POST['links3_name'],
            // 'links4_name'=>$_POST['links4_name'],
            // 'links1_link'=>$_POST['links1_link'],
            // 'links2_link'=>$_POST['links2_link'],
            // 'links3_link'=>$_POST['links3_link'],
            // 'links4_link'=>$_POST['links4_link'],

            // //20170417新增
            'prodesc'=>$_POST['prodesc'],//产品描述
            'proformula'=>$_POST['proformula'],//产品配方
            'applicationscope'=>$_POST['applicationscope'],//适用范围
            'usagemethod'=>$_POST['usagemethod'],//使用方法
            'considerations'=>$_POST['considerations'],//注意事项
            'productionrecordnumber'=>$_POST['productionrecordnumber'],//生产备案号
            'productrecordnumber'=>$_POST['productrecordnumber'],//产品备案号
            'specificationmodel'=>$_POST['specificationmodel'],//规格型号
            // 'productiondata' =>$_POST['productiondata'],

            );        
        if($sfy > 0){
           // $db->autoExecute($ecs->table('security_basics'), $data, 'UPDATE', "goods_id = '$goods_id'");
            $re = M('security_basics')->where("goods_id='$goods_id' and supplier_id='$supplier_id'")->save($data);
            if($re!==false)
            {
                //$this->success('新增成功', U('Qrcode/qr_listc'));
                echo "<script>
                alert('提交成功');
                history.back(-1)</script>";
            }else{
                 $this->error('请填写有效的信息！');
            }
        }else{
            $data['goods_id'] = $goods_id;
            $data['supplier_id'] = $supplier_id;
            $re = M('security_basics')->add($data);
            if($re!==false)
            {
                //$this->success('新增成功', U('Qrcode/qr_listc'));
                echo "<script>
                alert('提交成功');
                history.back(-1)</script>";
            }else{
                 $this->error('请填写有效的信息！');
            }
        }
    }
    //商品信息  补充信息
    public function addbuchonginfoSub()
    {       
        $goods_id = I('post.goods_id');
        $data = I('post.');
        //查询分类
        $term_id = M('goods')->where('goods_id='.$goods_id)->getField('term_id');
        //print_r($data);
        $re = M('security_info_'.$term_id)->add($data);
        //echo M('security_info_'.$term_id)->getLastSql();
        if($re)
        {
            $this->success('新增成功');
        }else{
                 $this->error('请填写有效的信息！');
        }
    }
    //追溯信息列表
    public function zhuisuInfo()
    {
        $goods_id = I('get.goods_id');
        $supplier_id = I('get.supplier_id');      
        $Obj = M('security_info'); // 实例化User对象
        //$map = array('status'=>'1');
        $where = "goods_id=$goods_id and supplier_id=$supplier_id";
        if(I('post.keywords',''))
        {
            $where .= " and supplier_name like '%".I('post.keywords')."%'";
        }
        $count      = $Obj->where($where)->count();// 查询满足要求的总记录数
        $Page       = new \Think\Page($count,15);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        // $Page->setConfig('prev',"上一页");
        // $Page->setConfig('next',"下一页");
        // 
        $Page->setConfig('header','<span class="total">共<b>%TOTAL_ROW%</b>条数据，第<b>%NOW_PAGE%</b>页/共<b>%TOTAL_PAGE%</b>页</span>');
        $Page->setConfig('prev','上一页');
        $Page->setConfig('next','下一页');
        $Page->setConfig('last','末页');
        $Page->setConfig('first','首页');
        $Page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
        //分页跳转的时候保证查询条件
       // $Page->parameter = '';
        // $Page->parameter   .=   "supplier_name  ='$keywords'";
         //echo $Page->parameter;
        $show       = $Page->show();// 分页显示输出// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
        $list = $Obj
        ->alias('a')
        ->field("a.*,t.name")
        ->join("left join fwzs_terms as t on t.term_id = a.cat_id")
        ->order('sort,id desc')
        ->where($where)
        ->limit($Page->firstRow.','.$Page->listRows)
        ->select();
        $this->assign('listinfo',$list);// 赋值数据集
        $this->assign('page',$show);// 赋值分页输出 
        $this->assign('goods_id',$goods_id);
        $this->assign('supplier_id',$supplier_id);
        $this->display('zhuisuinfo');
    }
    //追溯信息添加
    public function addZhuisuInfo()
    {
         $goods_id = I('get.goods_id');
        $supplier_id = I('get.supplier_id');
       // print_r(I('get.'));
       //分类展示
        $field = array('term_id','name','parent_id');  
        $row = $this->allCategory($field);  
        //生成无限极分类  
        $list=$this->tree($row);  
        $this->assign('row',$list); 
        $this->assign('goods_id',$goods_id);
        $this->assign('supplier_id',$supplier_id);
        $this->display('addzhuisu');
    }
    //追溯信息添加  处理提交数据
    public  function addZhuisuSub()
    {
      //  echo $_POST['add_time'];
        $addtime = strtotime($_POST['add_time']);
        $data =array(
        'supplier_id'=>$_POST['supplier_id'],
        'goods_id'=>$_POST['goods_id'],
        'dcontent'=>$_POST['dcontent'],
        'fuzeren'=>$_POST['fuzeren'],
        'add_time'=>$addtime,
        'is_open'=>$_POST['is_open'],
        'cat_id'=>$_POST['cat_id'],
        'sort'=>$_POST['sort'],
        'title_name'=>$_POST['title_name'],
        'zy_con'=>$_POST['zy_con'],
        'shangjia'=>$_POST['shangjia'],
        );
        $re = M('security_info')->add($data);
      //  echo M('security_info')->getLastSql();
        if($re){  
            $supplier_id = $_POST['supplier_id'];
            $goods_id = $_POST['goods_id'];

          $this->success('添加成功',U("/Supplier/Qrcode/zhuisuInfo/supplier_id/$supplier_id/goods_id/$goods_id"),1);
        } else {   
         
         $this->error('请填写有效的信息！');
        }
  //  $GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('security_info'), $data, 'INSERT');
    }
    //修改防伪追溯信息
    public function editZhuisuInfo()
    {
        $goods_id = I('get.goods_id');
        $supplier_id = I('get.supplier_id');
        //  信息内容
        $data = M('security_info')->where("id = ".I('get.id'))->find();
       // print_r(I('get.'));
       //分类展示
        $field = array('term_id','name','parent_id');  
        $row = $this->allCategory($field);  
        //生成无限极分类  
        $list=$this->tree($row);  
        $this->assign('row',$list); 
        $this->assign('goods_id',$goods_id);
        $this->assign('data',$data);

        $this->assign('supplier_id',$supplier_id);
        $this->display('editzhuisu');
    }
    //修改防伪追溯信息 数据处理
    public function editZhuisuInfoSub()
    {
        $addtime = strtotime($_POST['add_time']);
        $data =array(
        'supplier_id'=>$_POST['supplier_id'],
        'goods_id'=>$_POST['goods_id'],
        'dcontent'=>$_POST['dcontent'],
        'fuzeren'=>$_POST['fuzeren'],
        'add_time'=>$addtime,
        'is_open'=>$_POST['is_open'],
        'cat_id'=>$_POST['cat_id'],
        'sort'=>$_POST['sort'],
        'title_name'=>$_POST['title_name'],
        'zy_con'=>$_POST['zy_con'],
        'shangjia'=>$_POST['shangjia'],
        );
        $re = M('security_info')->where("id = ".I('post.id'))->save($data);
     //echo M('security_info')->getLastSql();
        if($re!==false){    
          $this->success('修改成功',U('Qrcode/qr_listc'));
        } else {   
         
         $this->error('请填写有效的信息！');
        }
    }
    //删除防伪追溯洗洗
    public function delZhuisuInfo()
    {
         $re = M('security_info')->where("id = ".I('get.id'))->delete();
         if($re!==false){    
          $this->success('删除成功');
        } else {   
         
          $this->error('删除失败，请重新删除');
        }
    }
    //防伪码  列表
    public function fwmList()
    {
        $goods_id = I('get.goods_id');
        $supplier_id = I('get.supplier_id');      
        $Obj = M('security_qr'); // 实例化User对象
        //$map = array('status'=>'1');
        $where = "a.goods_id=$goods_id and a.supplier_id=$supplier_id";
        if(I('post.keywords',''))
        {
            $where .= " and supplier_name like '%".I('post.keywords')."%'";
        }
        $count      = $Obj
        ->alias('a')
        ->field("a.*,b.goods_name")
        ->join("left join fwzs_goods as b on b.goods_id = a.goods_id")
        // ->join("left join fwzs_goods as b on b.goods_id = a.goods_id")
        ->order('a.qr_id desc')
        ->where($where)
        ->count();// 查询满足要求的总记录数
        $Page       = new \Think\Page($count,15);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        // $Page->setConfig('prev',"上一页");
        // $Page->setConfig('next',"下一页");
        // 
        $Page->setConfig('header','<span class="total">共<b>%TOTAL_ROW%</b>条数据，第<b>%NOW_PAGE%</b>页/共<b>%TOTAL_PAGE%</b>页</span>');
        $Page->setConfig('prev','上一页');
        $Page->setConfig('next','下一页');
        $Page->setConfig('last','末页');
        $Page->setConfig('first','首页');
        $Page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
        //分页跳转的时候保证查询条件
       // $Page->parameter = '';
        // $Page->parameter   .=   "supplier_name  ='$keywords'";
         //echo $Page->parameter;
        $show       = $Page->show();// 分页显示输出// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
        $list = $Obj
        ->alias('a')
        ->field("a.*,b.goods_name,c.supplier_name")
        ->join("left join fwzs_goods as b on b.goods_id = a.goods_id")
        ->join("left join fwzs_security as c on c.supplier_id = a.supplier_id")
        ->order('a.qr_id desc')
        ->where($where)
        ->limit($Page->firstRow.','.$Page->listRows)
        ->select();


        $this->assign('listinfo',$list);// 赋值数据集
        $this->assign('page',$show);// 赋值分页输出 
        $this->assign('goods_id',$goods_id);
        $this->assign('supplier_id',$supplier_id);
         
        $this->display('fwmlist');
    }
    //冻结防伪码
    public function fwmDongjie()
    {
        $qr_id = I('get.qr_id');
        $re = M('security_qr')->where("qr_id=".$qr_id)->save(array('qr_start'=>1));
        if($re!==false){    
          $this->success('冻结成功');
        } else {   
         
          $this->error('冻结失败');
        }
    }
     //解冻防伪码
    public function fwmJiedong()
    {
        $qr_id = I('get.qr_id');
        $re = M('security_qr')->where("qr_id=".$qr_id)->save(array('qr_start'=>0));
        if($re!==false){    
          $this->success('解冻成功');
        } else {   
         
          $this->error('解冻失败');
        }
    }
    //删除防伪码
    public function delFwm()
    {
         $qr_id = I('get.qr_id');
        $re = M('security_qr')->where("qr_id=".$qr_id)->delete();
        if($re){    
          $this->success('删除成功');
        } else {   
         
          $this->error('删除失败');
        }
    }
    //轮播图列表
    public function lunboList()
    {
        $goods_id = I('get.goods_id');
        $supplier_id = I('get.supplier_id');      
        $Obj = M('security_lunbo'); // 实例化User对象
        //$map = array('status'=>'1');
        $where = "a.goods_id=$goods_id and a.supplier_id=$supplier_id";
        if(I('post.keywords',''))
        {
            $where .= " and supplier_name like '%".I('post.keywords')."%'";
        }
        $count      = $Obj
        ->alias('a')        
        ->order('a.id desc')
        ->where($where)
        ->count();// 查询满足要求的总记录数
        $Page       = new \Think\Page($count,15);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        // $Page->setConfig('prev',"上一页");
        // $Page->setConfig('next',"下一页");
        // 
        $Page->setConfig('header','<span class="total">共<b>%TOTAL_ROW%</b>条数据，第<b>%NOW_PAGE%</b>页/共<b>%TOTAL_PAGE%</b>页</span>');
        $Page->setConfig('prev','上一页');
        $Page->setConfig('next','下一页');
        $Page->setConfig('last','末页');
        $Page->setConfig('first','首页');
        $Page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
        //分页跳转的时候保证查询条件
       // $Page->parameter = '';
        // $Page->parameter   .=   "supplier_name  ='$keywords'";
         //echo $Page->parameter;
        $show       = $Page->show();// 分页显示输出// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
        $list = $Obj
        ->alias('a')
         
        ->order('a.id desc')
        ->where($where)
        ->limit($Page->firstRow.','.$Page->listRows)
        ->select();
        $this->assign('listinfo',$list);// 赋值数据集
        $this->assign('page',$show);// 赋值分页输出 
        $this->assign('goods_id',$goods_id);
        $this->assign('supplier_id',$supplier_id);
        $this->display('lunbolist');
    }
    //轮播添加
    public  function addLunbo()
    {
        $goods_id = I('get.goods_id');
        $supplier_id = I('get.supplier_id'); 
        $this->assign('goods_id',$goods_id);
        $this->assign('supplier_id',$supplier_id);
        $this->display('addlunbo');
    }
    public function addLunboSub()
    {
       // var_dump(I('post.face180'));
        if(I('post.face180'))
        {
            $ad_code = I('post.face180');

        }
        if (!empty($_POST['img_url']))
        {
            $ad_code = $_POST['img_url'];
        }
        $addtime = time();
        $data =array(
            'supplier_id'=>$_POST['supplier_id'],
            'goods_id'=>$_POST['goods_id'],
            'lunbo_weizhi'=>$_POST['lunbo_weizhi'],
            'imgurl'=>$ad_code,
            'dzrul'=>$_POST['dzrul'],
            'is_open'=>$_POST['is_open'],
            'sort'=>$_POST['sort'],
            'add_time'=>$addtime,
            );
       // print_r($data);
       $re = M('security_lunbo')->add($data);
        if($re){    
          $this->success('添加成功',U('Qrcode/lunboList',array('goods_id'=>$_POST['goods_id'],'supplier_id'=>$_POST['supplier_id'])));
        } else {   
         
          $this->error('添加失败');
        }
     }
     //删除轮播
     public function delLunbo()
     {
        $id = I('get.id');
        $re = M('security_lunbo')->where('id='.$id)->delete();
        if($re){    
            $this->success('删除成功');
        } else {   
            $this->error('删除失败');
        }
     }
     //修改轮播
     public function editLunbo()
     {
        $id = I('get.id');
        $data = M('security_lunbo')->where('id='.$id)->find();
        $this->assign('data',$data);
        $this->display('editlunbo');
     }
     public function editLunboSub()
     {
        //print_r(I('post.'));
        if(I('post.face180'))
        {
            $ad_code = I('post.face180');

        }else{
            $ad_code = I('post.img_url');
        }
        //imgurl
        $data = I('post.');
        $data['imgurl'] = $ad_code;
        $re = M('security_lunbo')->where('id='.I('post.id'))->save($data);
         if($re!==false){    
           $this->success('修改成功',U('Qrcode/lunboList',array('goods_id'=>$_POST['goods_id'],'supplier_id'=>$_POST['supplier_id'])));
        } else {   
         
          $this->error('修改失败');
        }
     }
     //检测信息
     public function jianceList()
     {
      //  echo '234234';
        $goods_id = I('get.goods_id');
        $supplier_id = I('get.supplier_id'); 
        $Obj = M('security_fwinfo'); // 实例化User对象
        //$map = array('status'=>'1');
        $where = "a.goods_id=$goods_id and a.supplier_id=$supplier_id";
        if(I('post.keywords',''))
        {
            $where .= " and supplier_name like '%".I('post.keywords')."%'";
        }
        $count      = $Obj
        ->alias('a')        
        ->order('a.id desc')
        ->where($where)
        ->count();// 查询满足要求的总记录数
        $Page       = new \Think\Page($count,15);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        // $Page->setConfig('prev',"上一页");
        // $Page->setConfig('next',"下一页");
        // 
        $Page->setConfig('header','<span class="total">共<b>%TOTAL_ROW%</b>条数据，第<b>%NOW_PAGE%</b>页/共<b>%TOTAL_PAGE%</b>页</span>');
        $Page->setConfig('prev','上一页');
        $Page->setConfig('next','下一页');
        $Page->setConfig('last','末页');
        $Page->setConfig('first','首页');
        $Page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
        //分页跳转的时候保证查询条件
       // $Page->parameter = '';
        // $Page->parameter   .=   "supplier_name  ='$keywords'";
         //echo $Page->parameter;
        $show       = $Page->show();// 分页显示输出// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
        $list = $Obj
        ->alias('a')
         
        ->order('a.id desc')
        ->where($where)
        ->limit($Page->firstRow.','.$Page->listRows)
        ->select();
        $this->assign('listinfo',$list);// 赋值数据集
        $this->assign('page',$show);// 赋值分页输出 

        $this->assign('goods_id',$goods_id);
        $this->assign('supplier_id',$supplier_id);
        $this->display('jiancelist');
     }
     //添加检测信息
     public function addJiance()
     {
        $goods_id = I('get.goods_id');
        $supplier_id = I('get.supplier_id'); 
        $this->assign('goods_id',$goods_id);
        $this->assign('supplier_id',$supplier_id);
        $this->display('addjiance');
     }
     public function addJianceSub()
     {
         $jctime = strtotime($_POST['jctime']);
        $data =array(
        'supplier_id'=>$_POST['supplier_id'],
        'goods_id'=>$_POST['goods_id'],
        'jcxiangmu'=>$_POST['jcxiangmu'],
        'jcjieguo'=>$_POST['jcjieguo'],
        'jcdanwei'=>$_POST['jcdanwei'],
        'jcjieguo'=>$_POST['jcjieguo'],
        'fuzeren'=>$_POST['fuzeren'],
        'jctime'=>$jctime,
        'add_time'=>time(),
        'is_open'=>$_POST['is_open'],
        
        'sort'=>$_POST['sort'],
        );
   // $GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('security_fwinfo'), $data, 'INSERT');
         $re = M('security_fwinfo')->add($data);
        if($re){    
          $this->success('添加成功',U('Qrcode/jianceList',array('goods_id'=>$_POST['goods_id'],'supplier_id'=>$_POST['supplier_id'])));
        } else {   
         
          $this->error('添加失败');
        }
     }
     public function delJiance()
     {
        $id = I('get.id');
        $re = M('security_fwinfo')->where('id='.$id)->delete();
        if($re){    
          $this->success('删除成功');
        } else {   
         
          $this->error('删除失败');
        }
     }
     //修改
     public function editJiance()
     {
        $id = I('get.id');
        $data = M('security_fwinfo')->where('id='.$id)->find();
        $this->assign('data',$data);
        $this->display('editjiance');
     }
     //修改 检测信息
     public function editJianceSub()
     {
         $jctime = strtotime($_POST['jctime']);
          $data =array(     
        'jcxiangmu'=>$_POST['jcxiangmu'],
        'jcjieguo'=>$_POST['jcjieguo'],
        'jcdanwei'=>$_POST['jcdanwei'],
        'jcjieguo'=>$_POST['jcjieguo'],
        'fuzeren'=>$_POST['fuzeren'],
        'jctime'=>$jctime,
        'is_open'=>$_POST['is_open'],       
        'sort'=>$_POST['sort'],
        );
   // $GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('security_fwinfo'), $data, 'INSERT');
         $re = M('security_fwinfo')->where('id='.I('post.id'))->save($data);
        if($re){    
          $this->success('修改成功');
        } else {   
         
          $this->error('修改失败');
        }
     }

     public function plchange()
     {
        $data = I();
        $type = $data['type'];

        // var_dump($type);
        // die;

        $choosed = $data['choosed'];
        $uid = $_SESSION['supplier']['supplier_id'];


        $start = $data['start'];
        $end = $data['end'];


        if ($choosed && $end != '') {
            $this -> error('调整失败，选中复选框的情况下不允许再填写起始和末尾值',U("/Supplier/Qrcode/goodsList/supplier_id/$uid"),1);
        }

        if ($choosed && $start != '') {
            $this -> error('调整失败，选中复选框的情况下不允许再填写起始和末尾值',U("/Supplier/Qrcode/goodsList/supplier_id/$uid"),1);
        }
        
        $security_qr = M('security_qr');
        $map['supplier_id'] = $uid;
        if ($type == 'changeg') {
            unset($data['type']);
            $goods_id = $data['goods_id'];
            if ($goods_id == '') {
                $this -> error('调整失败，请选择商品',U("/Supplier/Qrcode/goodsList/supplier_id/$uid"),1);
            }
            if ($choosed) {
                foreach ($choosed as $k => $v) {
                    $map['qr_id'] = $v;
                    $security_qr -> goods_id = $goods_id;
                    $security_qr -> where($map) -> save();
                }
            }else{
                if ($start == '') {
                     $this -> error('调整失败，请填写起始值',U("/Supplier/Qrcode/goodsList/supplier_id/$uid"),1);
                }

                if ($end == '') {
                    $this -> error('调整失败，请填写结束值',U("/Supplier/Qrcode/goodsList/supplier_id/$uid"),1);
                }

                if ($start == $end) {
                    $this -> error('调整失败，两个值相等没有区间',U("/Supplier/Qrcode/goodsList/supplier_id/$uid"),1);
                }

                if ($start > $end) {
                    $n1 = $end;
                    $n2 = $start;
                }else{
                    $n1 = $start;
                    $n2 = $end;
                }

                for ($a=$n1; $a <= $n2; $a++) { 
                    // 判断用户所输入的防伪码编号是否为自己的
                    $item = $security_qr -> where("qr_id = $a") -> find();
                    if ($item['supplier_id'] == $uid) {
                        $map['qr_id'] = $a;
                        $security_qr -> goods_id = $goods_id;
                        $security_qr -> where($map) -> save();
                    }
                }
            }

            $this -> success('修改成功',U("/Supplier/Qrcode/goodsList/supplier_id/$uid"),1);
        }else if($type == 'changeh'){
            unset($data['type']);
            $sf_hongbao = $data['sf_hongbao'];
            if ($choosed) {
                foreach ($choosed as $k => $v) {
                    $map['qr_id'] = $v;
                    $security_qr -> sf_hongbao = $sf_hongbao;
                    $security_qr -> where($map) -> save();
                }
            }else{
                if ($start == '') {
                     $this -> error('调整失败，请填写起始值',U("/Supplier/Qrcode/goodsList/supplier_id/$uid"),1);
                }

                if ($end == '') {
                    $this -> error('调整失败，请填写结束值',U("/Supplier/Qrcode/goodsList/supplier_id/$uid"),1);
                }

                if ($start == $end) {
                    $this -> error('调整失败，两个值相等没有区间',U("/Supplier/Qrcode/goodsList/supplier_id/$uid"),1);
                }

                if ($start > $end) {
                    $n1 = $end;
                    $n2 = $start;
                }else{
                    $n1 = $start;
                    $n2 = $end;
                }

                for ($a=$n1; $a <= $n2; $a++) { 
                    // 判断用户所输入的防伪码编号是否为自己的
                    $item = $security_qr -> where("qr_id = $a") -> find();
                    if ($item['supplier_id'] == $uid) {
                        $map['qr_id'] = $a;
                        $security_qr -> sf_hongbao = $sf_hongbao;
                        $security_qr -> where($map) -> save();
                    }
                }
            }
            $this -> success('修改成功',U("/Supplier/Qrcode/goodsList/supplier_id/$uid"),1);
        }
    }

    public function edit_qr($value='')
    {
        $qr_id = I('get.qr_id');   

        $security_qr = M("security_qr");

        $data = $security_qr -> where("qr_id = $qr_id") -> field('sf_hongbao,hb_moeny') -> find();
        // var_dump($qr_id);

        $this -> assign('qr_id',$qr_id);
        $this -> assign('data',$data);
        $this -> display();
    }

    public function editqrsub()
    {
        $uid = $_SESSION['supplier']['supplier_id'];
        $qr_id = I('post.qr_id');
        $sf_hongbao = I('post.sf_hongbao');
        $hb_moeny = I('post.hb_moeny');

        $security_qr = M("security_qr");

        $security_qr -> sf_hongbao = $sf_hongbao;
        $security_qr -> hb_moeny = $hb_moeny;

        $res = $security_qr -> where("qr_id = $qr_id") -> save();
        if ($res) {
           $this -> success('修改成功',U("/Supplier/Qrcode/goodsList/supplier_id/$uid"),1);
        }else{
            $this -> error('修改失败',U("/Supplier/Qrcode/goodsList/supplier_id/$uid"),1);
        }
    }

    public function ajaxget(){

        $uid = I('post.supplier_id');
        // 获取该商户下的商品
        $goods = M('goods');

        $gdata = $goods -> field('goods_id,goods_name') -> where("supplier_id = $uid") -> select();

        $this -> ajaxReturn($gdata);
    }
}